#ifndef _BOOT_LOADER_H_
#define _BOOT_LOADER_H_

#include "ui/ui_sprite.h"
#include "math/counter.h"
#include "input/keyboard.h"
#include "input/mouse.h"

#include "audio/audio.h"
class AVI;
#include <vector>

class BootLoader : public input::KeyboardListener, public input::MouseListener
{
public:
	BootLoader(bool AllowSkip = true);
	~BootLoader();

	void			Tick();
	void			Render();
	void			Load(const std::string& File);
	bool			AddPage(const std::string& Image, float StayTime = 3.0f, float FadeIn = 1.0f, float FadeOut=1.0f, bool IsAvi = false, const std::string& PlaySoundEvent = "", bool AllowSkip = true);
	bool			IsDone() const { return m_IsDone; }
	void			SetSpeedSkip(bool b) { m_SpeedSkip = b; };

	bool			VISTA_SKIP_BUG;

private:
	bool			ValidState(int Index);
	void			GoState(int Index);
	struct			Page
	{
		Page() : StayTime(0), FadeIn(0), FadeOut(0), pVideo(0), Sound(0), AllowSkip(false) {};

		float			StayTime;
		float			FadeIn;
		float			FadeOut;
		std::string		File;
		ui::UISprite	Sprite;
		AVI*			pVideo;
		std::string		PlaySoundEvent;
		audio::AudioFile	Sound;
		bool			AllowSkip;
	};
	std::vector<Page*>	m_Pages;
	int				m_CurrentIndex;
	math::Counter	m_FadeIn, m_Stay, m_FadeOut;
	bool			m_IsDone;
	bool			m_AllowSkip;
	bool			m_SpeedSkip;
	bool			m_HasSkipped;

	// user wants to skip this!
	void				SpeedupTransition();
	// outside events
	virtual void		KeyReleased(input::Keyboard::KEY* pKey) {	if (m_AllowSkip) SpeedupTransition(); };
	virtual void		MouseButtonReleased(input::Mouse::BUTTON_STATE* pKey, const math::Vec2& Pos) {	if (m_AllowSkip) SpeedupTransition(); };
};

#endif // _BOOT_LOADER_H_